package me.zhengjie.repository;

import me.zhengjie.base.BaseEntity;
import me.zhengjie.pojo.sqlServer.PPStation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface PPStationRepository extends JpaRepository<PPStation, Integer>, JpaSpecificationExecutor<PPStation> {

    @Query("update PPStation set stationStatus=?1 where stationCode=?2")
    int updatePPStationByCode(Integer status, String stationCode);

    @Query("select pp from PPStation pp  where pp.stationCode=?1")
    PPStation getByStationCode(String stationCode);

    @Query("select pp from PPStation pp where pp.stationName=?1")
    List<PPStation> findAllByStationName(String stationName);

    //查看没被占用的工作站
    @Query("select pp from PPStation pp where pp.takeStatus=0")
    List<PPStation> findFreeStation();


    @Modifying
    @Query("update PPStation set takeStatus =1 where stationCode=?1")
    int lockStation(String destination);


    @Modifying
    @Query("update PPStation set takeStatus =0 where stationCode=?1")
    int refeaseStation(String destination);


    PPStation findPPStationsByStationCode(String destination);

    PPStation findByStationCode(String fromLocation);
}
